<template>
  <div>
    <!-- 卡片 -->
    <el-card class="box-card office_soft">
      <!-- 头部 -->
      <div slot="header" class="clearfix office_soft_header">
        <!-- 返回 -->
        <div class="back" @click="backClick">
          <i></i>
          <span>返回</span>
        </div>
      </div>

      <!-- 办公软件卡片 -->
      <el-card>
        <div class="off_soft">
          <h1>办公软件</h1>
          <div class="off_right">
            <el-input
              placeholder="腾讯QQ"
              style="color:lightgreen;"
              suffix-icon="el-icon-search"
              v-model="input1"
            ></el-input>
            <div class="add" @click="addSoftware">+ 添加软件</div>
          </div>
        </div>
        <div class="off_table">
          <el-table
            :header-cell-style="{background:'#E9F4FD',color:'#212121',fontSize:'22px'}"
            :data="tableData"
            style="width: 100%"
          >
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column fixed prop="name" label="软件名称"></el-table-column>
            <el-table-column fixed="right" label="操作" width="200px">
              <template slot-scope="scope">
                <el-button @click="handleClick(scope.row)" type="text">修改</el-button>
                <el-button type="text" @click="handleDel(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 页码 -->
        <div class="block off_page">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="1"
            :page-sizes="[5,10, 15,20]"
            :page-size="100"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalSize"
          ></el-pagination>
        </div>
      </el-card>
    </el-card>
  </div>
</template>


<script>
export default {
  methods: {
    backClick() {
      this.$router.go(-1);
    },
    // 点击修改
    handleClick(row) {
      console.log(row);
      this.row = row
      this.$router.push({ path: "/modify_software", query: { token: this.token, row: this.row } });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      // console.log(val);
      this.page.pageSize = val
      this.getSoftWare()
    },
    handleCurrentChange(val) {
      // console.log(val);
      this.page.pageNum = val
      this.getSoftWare()
    },
    // 点击添加软件
    addSoftware() {
      // this.$router.push("./add_software");
      this.$router.push({ path: "/add_software", query: { token: this.token } });

    },
    // 软件应用
    getSoftWare() {
      this.$axios.get("http://47.105.140.58:8084/applicationprograms/program",{
        params:{
          pageNum: this.page.pageNum,
          pageSize: this.page.pageSize  //每页显示几条数据
        }
      }).then(res=>{
        console.log(res);
        this.tableData = res.data.content
        this.totalSize = res.data.totalSize
        this.page.pageSize = res.data.pageSize
        this.page.pageNum = res.data.pageNum
      })
    },

    // 点击删除
    handleDel(id) {
      // console.log(id.uuid);
      this.$axios.delete('http://47.105.140.58:8084/applicationprograms/deleteProgram',id.uuid).then(res=>{
        console.log(res);
        this.$message.success('success')
      })
    }
  },
  data() {
    return {
      input1: "",
      tableData: [],
      page:{
        pageNum:1,  //当前页码
        pageSize:5  //每页几条数据
      },
      totalSize:0,  //总条数
      token: this.$route.query.token,
      row:'',
    };
  },
  mounted() {
    this.getSoftWare() //获取页面数据
    
  }
};
</script>


<style>
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}
.office_soft_header {
  margin: 10px 0 9px 30px;
  position: relative;
}
.office_soft .el-card__header {
  padding-bottom: 50px;
}
.office_soft_header i {
  /* display: block; */
  position: absolute;
  top: 5px;
  left: 0;
  width: 10px;
  height: 20px;
  background: url("../assets/img/left.png") no-repeat;
  background-size: 10px 20px;
  vertical-align: middle;
}
.office_soft_header span {
  position: absolute;
  top: 0px;
  left: 22px;
  margin: 0;
  font-size: 20px;
  color: #3f51b5;
}
.office_soft_header h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 400;
  text-align: center;
  color: #212121;
}
.off_soft h1 {
  display: inline;
  font-size: 32px;
  color: #4c4c4c;
}
/* 右侧搜索框 */
.off_right {
  float: right;
}
.off_right .el-input {
  float: left;
  width: 276px;
  height: 40px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  vertical-align: middle;
  border: none;
}
.off_right .add {
  float: left;
  padding: 10px;
  color: #3040a0;
  font-size: 18px;
}
/* 表格 */
.off_table {
  margin-top: 32px;
}
/* 页码 */
.off_page {
  margin-top: 33px;
  text-align: center;
}
.off_table .el-table {
  font-size: 18px;
  color: #212121;
}
.off_table .el-button--text {
  color: #212121;
}
.off_table .el-button {
  font-size: 18px;
}
</style>